﻿<template>
  <a-drawer
    :title="title"
    width="90%"
    :visible="visible"
    :confirmLoading="loading"
    @close="
      () => {
        this.visible = false
      }
    "
  >
    <a-form-model ref="form" :model="entity" :rules="rules" v-bind="layout">
      <a-row>
        <a-col :span="8">
          <a-form-model-item label="编码" prop="cInvCode">
            <a-input v-model="entity.cInvCode" autocomplete="off" placeholder="存货编码" />
          </a-form-model-item>
        </a-col>
        <a-col :span="8">
          <a-form-model-item label="名称" prop="cInvName">
            <a-input v-model="entity.cInvName" autocomplete="off" placeholder="存货名称" />
          </a-form-model-item>
        </a-col>
        <a-col :span="8">
          <a-form-model-item label="规格型号" prop="cInvStd">
            <a-input v-model="entity.cInvStd" autocomplete="off" placeholder="规格型号" />
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row>
        <a-col :span="8">
          <a-form-model-item label="计量单位">
            <a-input v-model="entity.iVolume" autocomplete="off" placeholder="计量单位" />
          </a-form-model-item>
        </a-col>
        <a-col :span="8">
          <a-form-model-item label="计划价或售价" prop="iInvRCost">
            <a-input v-model="entity.iInvRCost" autocomplete="off" placeholder="计划价或售价" />
          </a-form-model-item>
        </a-col>
        <a-col :span="8">
          <a-form-model-item label="参考成本">
            <a-input v-model="entity.iInvSPrice" autocomplete="off" placeholder="参考成本" />
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row>
        <a-col :span="8">
          <a-form-model-item label="参考售价">
            <a-input v-model="entity.iInvSCost" autocomplete="off" placeholder="参考售价" />
          </a-form-model-item>
        </a-col>
        <a-col :span="8">
          <a-form-model-item label="最低售价">
            <a-input v-model="entity.iInvLSCost" autocomplete="off" placeholder="最低售价" />
          </a-form-model-item>
        </a-col>
        <a-col :span="8">
          <a-form-model-item label="最新成本">
            <a-input v-model="entity.iInvNCost" autocomplete="off" placeholder="最新成本" />
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row>
        <a-col :span="8">
          <a-form-model-item label="最高售价">
            <a-input v-model="entity.iHighPrice" autocomplete="off" placeholder="最高售价" />
          </a-form-model-item>
        </a-col>
        <a-col :span="8">
          <a-form-model-item label="零售价格">
            <a-input v-model="entity.fRetailPrice" autocomplete="off" placeholder="零售价格" />
          </a-form-model-item>
        </a-col>
      </a-row>
    </a-form-model>
    <div
      :style="{
        position: 'absolute',
        right: 0,
        bottom: 0,
        width: '100%',
        borderTop: '1px solid #e9e9e9',
        padding: '10px 16px',
        background: '#fff',
        textAlign: 'right',
        zIndex: 1
      }"
    >
      <a-button @click="close">取消</a-button>&nbsp;
      <a-button type="primary" @click="handleSubmit">保存</a-button>
    </div>
  </a-drawer>
</template>

<script>
export default {
  props: {
    parentObj: Object
  },
  data() {
    return {
      layout: {
        labelCol: { span: 5 },
        wrapperCol: { span: 18 }
      },
      visible: false,
      loading: false,
      entity: {},
      rules: {},
      title: ''
    }
  },
  methods: {
    close() {
      this.visible = false

      this.entity = {}
    },
    init() {
      this.visible = true
      this.entity = {}
      this.$nextTick(() => {
        this.$refs['form'].clearValidate()
      })
    },
    openForm(id, title) {
      this.init()
      this.title = title
      if (id) {
        this.loading = true
        this.$http.post('/ProductManagement/Inventory/GetTheData', { id: id }).then(resJson => {
          this.loading = false

          this.entity = resJson.Data
        })
      }
    },
    handleSubmit() {
      this.$refs['form'].validate(valid => {
        if (!valid) {
          return
        }
        this.loading = true
        this.$http.post('/ProductManagement/Inventory/SaveData', this.entity).then(resJson => {
          this.loading = false

          if (resJson.Success) {
            this.$message.success('操作成功!')
            this.visible = false

            this.parentObj.getDataList()
          } else {
            this.$message.error(resJson.Msg)
          }
        })
      })
    }
  }
}
</script>
